Skip to content

Add __code__ to types.MethodType#12749

Merged
srittau merged 2 commits intopython:mainfrom
Avasam:Add-__code__-to-MethodType
Oct 8, 2024
Merged

Add __code__ to types.MethodType#12749
srittau merged 2 commits intopython:mainfrom
Avasam:Add-__code__-to-MethodType

Conversation

@Avasam
Copy link
Collaborator

@Avasam Avasam commented Oct 6, 2024

I have no idea if this is even correct. But here's the PR that made me add this: mhammond/pywin32#2385 and here's a short repro:

import types

class A:
    def test(self): ...

print(type(A().test) is types.MethodType)
print(A().test.__code__)
A().test.__code__ = None

results in:

True
<code object test at 0x00000236894BB660, file "c:\Users\Avasam\Desktop\import types.py", line 4>
Traceback (most recent call last):
  File "c:\Users\Avasam\Desktop\import types.py", line 8, in <module>
    A().test.__code__ = None
AttributeError: 'method' object has no attribute '__code__'

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weird one, but the change look kinda correct to me.

@srittau srittau merged commit 1f4031c into python:main Oct 8, 2024
@Avasam Avasam deleted the Add-__code__-to-MethodType branch October 8, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants